package com.fr.report.web.ui;

import com.fr.base.StringUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.core.DataXMLUtils;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.web.ui.reg.CustomReg;
import com.fr.report.web.ui.reg.RegExp;
import com.fr.web.Repository;

public class TextEditor extends FieldEditor
{
  private RegExp regex;
  private String waterMark;

  public String getXType()
  {
    return "text";
  }

  public RegExp getRegex()
  {
    return this.regex;
  }

  public void setRegex(RegExp paramRegExp)
  {
    this.regex = paramRegExp;
  }

  public void setWaterMark(String paramString)
  {
    this.waterMark = paramString;
  }

  public String getWaterMark()
  {
    return this.waterMark;
  }

  public JSONObject createJSONConfig(Object paramObject, Repository paramRepository)
    throws JSONException
  {
    JSONObject localJSONObject = super.createJSONConfig(paramObject, paramRepository);
    localJSONObject.put("render", true);
    if (this.regex != null)
      localJSONObject.put("regex", getRegex().toRegText());
    if (this.waterMark != null)
      localJSONObject.put("watermark", this.waterMark);
    return localJSONObject;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if ((str1.equals("TextAttr")) || ("Attributes".equals(str1)))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("allowBlank")) != null)
          setAllowBlank(Boolean.valueOf(str2).booleanValue());
      }
      else if (str1.equals("Reg"))
      {
        this.regex = DataXMLUtils.readXMLReg(paramXMLableReader);
      }
      else if (str1.equals("Regexp"))
      {
        setRegex(new CustomReg(paramXMLableReader.getElementValue()));
      }
      else if ("watermark".equals(str1))
      {
        setWaterMark(paramXMLableReader.getElementValue());
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("TextAttr");
    if (!(isAllowBlank()))
      paramXMLPrintWriter.attr("allowBlank", isAllowBlank());
    paramXMLPrintWriter.end();
    if (this.regex != null)
      ReportXMLUtils.writeXMLable(paramXMLPrintWriter, this.regex, "Reg");
    if (StringUtils.isNotBlank(this.waterMark))
      paramXMLPrintWriter.startTAG("watermark").textNode(this.waterMark).end();
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof TextEditor) && (super.equals(paramObject)) && (ComparatorUtils.equals(this.regex, ((TextEditor)paramObject).regex)));
  }
}